HTML is an application of ISO Standard 8879:1986 - Standard Generalized Markup Language (SGML). SGML is a system for defining structured document types and markup languages to represent instances of those document types[SGML]. The public text -- DTD and SGML declaration -- of the HTML document type definition are provided in section HTML Public Text.
The term HTML refers to both the document type defined here and the markup language for representing instances of this document type.
An HTML document is an SGML document; that is, a set of entities, including the document entity, which is text entity in which parsing begins. The first production of the SGML grammar separates an SGML document into three parts: an SGML declaration, a prologue, and an instance.
For the purposes of this specification, the prologue is a DTD. This DTD describes another grammar: the start symbol is given in the doctype declaration; the terminals are data characters and tags, and the productions are determined by the element declarations. The instance must conform to the DTD, that is, it must be in the language defined by this grammar.
The SGML declaration determines the lexicon of the grammar. It specifies the document character set, which determines a character repertoire that contains all characters that occur in all text entities in the document, and the character numbers associated with those characters.
The SGML declaration also specifies the syntax character set of the document, and a few other parameters that bind the abstract syntax of SGML to a concrete syntax. This concrete syntax determines how each text entity is mapped to a sequence of terminals in the grammar of the prologue.
For example, consider the following document:
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN"> <title>Parsing Example</title> <p>Some text. <em>*wow*</em>
An HTML user agent should use the SGML declaration is given in section SGML Declaration for HTML. It specifies ISO-8859-1 as the document character set, so that the markup `*' represents an asterisk character.
The instance above is regarded as the following sequence of terminals:
The start symbol of the DTD grammar is HTML, and the productions are given in the public text identified by `-//IETF//DTD HTML 2.0//EN' (section HTML DTD). Hence the terminals above parse as:
HTML | \-HEAD, BODY | | \-TITLE \-P | | | \-<P>,"Some text. ",EM | | | \-<EM>,"*wow*",</EM> \-<TITLE>,"Parsing Example",</TITLE>
The syntax character set for all HTML documents is ISO-646-IRV. A minimally conforming HTML user agent must support the SGML declaration in section SGML Declaration for HTML, which specifies ISO Latin 1 (@@full name) as the document character set; it may support other SGML declarations, in particular, SGML declarations with other document character sets.
A complete discussion of SGML parsing, e.g. the mapping of a sequence of characters to a sequence of tags and data is left to the SGML standard[SGML]. This section is only a summary.
Any sequence of characters that do not constitute markup (see "Delimiter Recognition," section @@@ of [SGML]) are mapped directly to strings of data characters. Some markup also maps to data character strings. Numeric character references also map to single-character strings, via the document character set. Each reference to one of the general entities defined in the HTML DTD also maps to a single-character string.
For example,
abc<def => "abc","<","def" abc<def => "abc","<","def"
Note that the terminating semicolon is only necessary when the character following the reference would otherwise be recognized as markup:
abc < def => "abc ","<"," def" abc < def => "abc ","<"," def"
And note that an ampersand is only recognized as markup when it is followed by a letter or number:
abc & lt def => "abc & lt def" abc & 60 def => "abc & 60 def"
A useful technique for translating plain text to HTML is to replace each '<', '&', and '>' by an entity reference or numeric character reference as follows:
ENTITY NUMERIC CHARACTER REFERENCE CHAR REF CHARACTER DESCRIPTION & & & Ampersand < < < Less than > > > Greater than
Tags delimit elements such as headings, paragraphs, lists, character highlighting and links. Most HTML elements are identified in a document as a start tag, which gives the element name and attributes, followed by the content, followed by the end tag. Start tags are delimited by `<' and `>'; end tags are delimited by `</' and `>'. An example is:
<H1>This is a Heading</H1>
Some elements only have a start tag without an end tag. For example, to create a line break, you use the `<BR>' tag. Additionally, the end tags of some other elements, such as Paragraph (`</P>'), List Item (`</LI>'), Definition Term (`</DT>'), and Definition Description (`<DD>') elements, may be omitted.
The content of an element is a sequence of data character strings and nested elements. Some elements, such as anchors, cannot be nested. Anchors and character highlighting may be put inside other constructs. See the HTML DTD, section HTML DTD for full details. (4)
A name consists of a letter followed by up to 71 letters, digits, periods, or hyphens. Element names are not case sensitive, but entity names are. For example, `<BLOCKQUOTE>', `<BlockQuote>', and `<blockquote>' are equivalent, whereas `&' is different from `&'.
In a start tag, the element name must immediately follow the tag open delimiter `<'.
In a start tag, white space and attributes are allowed between the element name and the closing delimiter. An attribute typically consists of an attribute name, an equal sign, and a value, though some attributes may be just a value. White space is allowed around the equal sign.
The value of the attribute may be either:
In this example, img is the element name, `src' is the attribute name, and `http://host/dir/file.gif' is the attribute value:
<img src="http://host/dir/file.gif">
A useful technique for computing an attribute value literal for a given string is to replace each quote and space character by an entity reference or numeric character reference as follows:
ENTITY NUMERIC CHARACTER REFERENCE CHAR REF CHARACTER DESCRIPTION TAB 	 Tab LF Line Feed CR Carriage Return   Space " " " Quotation mark & & & Ampersand
For example:
<IMG SRC="image.jpg" alt="First "real" example">
Note that the SGML declaration in section 13.3 limits the length of an attribute value to 1024 characters.
Attributes such as ISMAP and COMPACT, may be written using a minimized syntax. The markup:
<UL COMPACT="compact">
can be written using a minimized syntax:
<UL COMPACT>
To include comments in an HTML document that will be eliminated in the mapping to terminals, surround them with `'. After the comment delimiter, all text up to the next occurrence of `-->' is ignored. Hence comments cannot be nested. White space is allowed between the closing `--' and `>', but not between the opening `<!' and `--'.
For example:
<HEAD> <TITLE>HTML Guide: Recommended Usage</TITLE> <!-- $Id: HTML.txt,v 1.14 1995/04/26 16:07:52 connolly Exp $ --> </HEAD>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <HTML> <!-- Here's a good place to put a comment. --> <HEAD> <TITLE>Structural Example</TITLE> </HEAD><BODY> <H1>First Header</H1> <P>This is a paragraph in the example HTML file. Keep in mind that the title does not appear in the document text, but that the header (defined by H1) does.</P> <OL> <LI>First item in an ordered list. <LI>Second item in an ordered list. <UL COMPACT> <LI> Note that lists can be nested; <LI> Whitespace may be used to assist in reading the HTML source. </UL> <LI>Third item in an ordered list. </OL> <P>This is an additional paragraph. Technically, end tags are not required for paragraphs, although they are allowed. You can include character highlighting in a paragraph. <EM>This sentence of the paragraph is emphasized.</EM> Note that the </P> end tag has been omitted. <P> <IMG SRC ="triangle.xbm" alt="Warning:"> Be sure to read these <b>bold instructions</b>. </BODY></HTML>